const path = require('path')
const resolve = (dir) => path.join(__dirname, dir)
const webpack = require('webpack')

module.exports = {
  env: {
    NODE_ENV: '"development"'
  },
  defineConstants: {
  },
  mini: {},
  h5: {
    runtimeCompiler: true,
    lintOnSave: true,
    devServer: {
      /* 是否自动打开浏览器 */
      open: true,
      host: '0.0.0.0',
      port: '8080',
      /* 是否开户检测 */
      disableHostCheck: false,
      https: false,
      hotOnly: false,
      proxy: {
        '/api': {
          target: ''
        }
      }
    },
    webpackChain: (config) => {
      // 修改HMR
      config.resolve.symlinks(true)

      config.module
        .rule('eslint')
        .use('eslint-loader')
        .loader('eslint-loader')
        .tap ((options) => {
          options.fix = true
          return options
        })

      // 设置切片方式
      config.optimization.splitChunks({
        cacheGroups: {
          vendors: {
            name: 'chunk-vendors',
            minChunks: 2,
            test: /node_modules/,
            priority: -10,
            chunks: 'initial'
          },
          echarts: {
            name: 'echarts',
            test: /echarts|zrender/,
            priority: 10,
            chunks: 'all'
          }
        }
      })

      // 设置入口起点的最大体积500k（以字节为单位）
      config.performance.maxEntrypointSize(40000000)
      // 生成文件的最大体积 整数类型（以字节为单位 300k）
      config.performance.maxAssetSize(30000000)

      config.performance.assetFilter(function (assetFilename) {
        return assetFilename.endsWith('.js')
      })
    },
    configureWebpack: (config) => {}
  }
}
